//
//  playViewController.m
//  A1.0
//
//  Created by lanou3g on 15-4-2.
//  Copyright (c) 2015年 ccandxx. All rights reserved.
//

#import "playViewController.h"
#import "videoModel.h"
#import <MediaPlayer/MediaPlayer.h>
@interface playViewController ()

@property(nonatomic,strong)MPMoviePlayerViewController *moviePlayer;

@end

@implementation playViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self p_setupView];
    
}

- (void)p_setupView
{
    
    
    self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:_model.mp4_url]];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playVideoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:[self.moviePlayer moviePlayer]];
    
    self.moviePlayer.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
    [self.moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    
    [self.moviePlayer.moviePlayer setFullscreen:YES animated:YES];
    
    [self presentMoviePlayerViewControllerAnimated:self.moviePlayer];
    
    [self.moviePlayer.moviePlayer play];

    
    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
    [self.moviePlayer.view setTransform:transform];
    
    
   
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    
    
    [self.moviePlayer.view setFrame:[[UIScreen mainScreen]bounds]];
    
    
    [self.view addSubview:_moviePlayer.view];
    
 
    
}
- (void) playVideoFinished:(NSNotification *)theNotification//当点击Done按键或者播放完毕时调用此函数
{
    MPMoviePlayerController *player = [theNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [player stop];
    [self.moviePlayer  dismissMoviePlayerViewControllerAnimated];
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
